<!DOCTYPE html>
<html xmlns="http://www.thymeleaf.org">
<head>
<title>Insert title here</title>
<meta charset="UTF-8">
<base th:href="@{/}"/>
<link rel="stylesheet" th:href="@{/css/bootstrap.min.css}"/>
<link rel="stylesheet" th:href="@{/css/Managerstyle.css}"/>
<script th:src="@{/js/jquery-3.4.1.min.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>
</head>
<body>
	<div class="contain">
		<h3>学院管理</h3>
		<table class="table table-hover">
			<tr>
				<td>学院号</td>
				<td width="620">学院名称</td>
				<td>学院描述</td>
				<td width="320">操作</td>
			</tr>
			<tr th:each="acadamy:${acadamylist}" th:id="|tr${acadamy.acdmid}|">
				<td th:text="${acadamy.acdmid}"></td>
				<td th:text="${acadamy.acdmname}"></td>
				<td th:text="${acadamy.description}"></td>
				<td>
					<a th:href="|mc/to_modifyAcadamy/${acadamy.acdmid}|">编辑</a>
					<a th:href="|javascript:deleteAcadamy(${acadamy.acdmid});|">删除</a>
				</td>
			</tr>
		</table>
		<!-- Button trigger modal -->
		<button type="button" class="btn btn-success" data-toggle="modal" data-target="#addAcadamy">
		  添加新学院
		</button>
		<div class="text-center">
			<nav>
				<ul class="pagination">
					<li><a th:href="@{/mc/getAllAcadamy/(pageNo=1)}">首页</a></li>
					<li><a th:href="@{/mc/getAllAcadamy/(pageNo=${pageInfo.hasPreviousPage}?${pageInfo.prePage}:1)}">上一页</a></li>
					<li th:each="page:${pageInfo.navigatepageNums}">
						<a th:class="${pageInfo.pageNum}==${page}?'active'"
						   th:href="@{/mc/getAllAcadamy/(pageNo=${page})}">[[${page}]]</a>
					</li>
					<li><a th:href="@{/mc/getAllAcadamy/(pageNo=${pageInfo.hasNextPage}?${pageInfo.nextPage}:${pageInfo.pages})}">下一页</a></li>
					<li><a th:href="@{/mc/getAllAcadamy/(pageNo=${pageInfo.pages})}">尾页</a></li>
				</ul>
			</nav>
		</div>
		
		<!-- addModal -->
		<div class="modal fade" id="addAcadamy" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
		  <div class="modal-dialog" role="document">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        <h4 class="modal-title" id="myModalLabel">添加新学院</h4>
		      </div>
		      <form action="mc/addAcadamy" method="post">
		      <div class="modal-body">
					<dl class="dl-horizontal">
					  <dt><label for="acdmname">学院名称：</label></dt>
					  <dd><input type="text" maxlength="30" required="required" id="acdmname" name="acdmname" placeholder="在此输入学院名称"  class="form-control sinfo" style="width: 170px;"></dd>
					  <br>
					  <dt><label for="description">描述：</label></dt>
					  <dd><input type="text" id="description" name="description" placeholder="在此输入描述" class="form-control sinfo" style="width: 270px;"></dd>
					</dl>
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
		        <input type="submit" class="btn btn-primary" value="添 加">
		      </div>
		      </form>
		    </div>
		  </div>
		</div>
	</div>
	
	<script>
	        function deleteAcadamy(id) {
	            $.ajax({
	                url: 'mc/deleteAcadamy',
	                type: 'POST',
	                data: {acdmid: id}, 
	                success: function () {
	                	$("#tr" + id).remove(); 
	                },
	                error: function (req, status, error) {
	                    alert("Ajax请求失败，错误：" + error);
	                }
	            });
	        }
    </script>
</body>
</html>